package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.OperLog;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.domain.UserTb;
import com.ruoyi.system.mapper.OperLogMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.UserTbMapper;
import com.ruoyi.system.service.UserTbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserTbServiceImpl implements UserTbService{
    @Autowired
    private UserTbMapper userTbMapper;
    @Autowired
    private OperLogMapper operLogMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public List<UserTb> getAllGameUser(String key, Integer pageNum, Integer pageSize) {
        return userTbMapper.getAllGameUser(key,pageNum,pageSize);
    }

    @Override
    public Long getAllGameUserCount(String key, Integer pageNum, Integer pageSize) {
        return userTbMapper.getAllGameUserCount(key,pageNum,pageSize);
    }

    @Override
    public Long updateGameUserStatus(Integer status, Integer id,OperLog operLog) {
        //TODO 这里需要保存修改记录
        operLogMapper.insertOperLog(operLog);
        return userTbMapper.updateGameUserStatus(status,id);
    }

    @Override
    public UserTb selectGameUserById(int id) {
        return userTbMapper.selectGameUserById(id);
    }

    @Override
    public Long updateGameUserAgent(Integer isAgent, Integer id, OperLog operLog) {
        operLogMapper.insertOperLog(operLog);
        //解除代理时，需同时将该代理登录系统的权限取消
        if (isAgent==0){
            SysUser user = new SysUser();
            user.setStatus(1);
            user.setGameUserId(id.longValue());
            sysUserMapper.updateUserByGameUserId(user);
        }
        return userTbMapper.updateGameUserAgent(isAgent,id);
    }
}
